#include "MainFrame/CentralWidget/CentralWidget.h"
#include <QHBoxLayout>
#include "MainFrame/CentralWidget/CentralManager.h"

#include "MainFrame/CentralWidget/ImageTabWidget.h"

CentralWidget::CentralWidget(QWidget *parent) :
    QWidget(parent),
    m_pImageTabWidget(nullptr)
{
    initWidget();
    connetSignalToSlots();
    CentralManager::setCentralWidget(this);
}

CentralWidget::~CentralWidget()
{

}

void CentralWidget::initWidget()
{
    m_pImageTabWidget = new ImageTabWidget(this);

    QHBoxLayout* centralLayout = new QHBoxLayout;
    centralLayout->addWidget(m_pImageTabWidget, 0, 0);
    centralLayout->setMargin(5);

    this->setLayout(centralLayout);
}

void CentralWidget::connetSignalToSlots()
{
    connect(m_pImageTabWidget, SIGNAL(cursorPosChanged(QPoint&)),
            this, SIGNAL(cursorPosChanged(QPoint&)));
    connect(m_pImageTabWidget, SIGNAL(imageAdded(int,QString)),
            this, SIGNAL(imageAdded(int,QString)));
    connect(m_pImageTabWidget, SIGNAL(imageDeleted(int)),
            this, SIGNAL(imageDeleted(int)));
    connect(m_pImageTabWidget, SIGNAL(imageChanged(int)),
            this, SIGNAL(imageChanged(int)));
}

void CentralWidget::updateImageViewWidget()
{
    m_pImageTabWidget->updateImageViewWidget();
}

void CentralWidget::addImageViewWidget(const QString &imagename)
{
    m_pImageTabWidget->addImageViewWidget(imagename);
}

void CentralWidget::setEnCurToolState(const ToolState &enCurToolState)
{
    m_pImageTabWidget->setEnCurToolState(enCurToolState);
}
